package com.tongji.housediy.view
{
	import com.tongji.housediy.controller.CantavilCMD.GetCantavilNameCmd;
	import com.tongji.housediy.events.CantavilEvent.GetCantavilNameEvent;
	import com.tongji.housediy.model.CantavilDropDownListModel;
	import com.tongji.housediy.view.CityDropDownList;
	
	import flash.events.MouseEvent;
	
	import mx.events.FlexEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	import spark.events.IndexChangeEvent;
	
	public class CityDropDownListMediator extends Mediator
	{
		[Inject]
		public var view:CityDropDownList;
		
		[Inject]
		public var model:CantavilDropDownListModel;
		
		override public function onRegister():void
		{
			/*trace("aa", view.id);*/
			view.addEventListener(MouseEvent.CLICK, selectProvinceHandler);
			view.addEventListener(IndexChangeEvent.CHANGE, viewChangedHandler);
			view.addEventListener(FlexEvent.VALUE_COMMIT, valueCommitHandler);
		}
		
		private function selectProvinceHandler(event:MouseEvent):void
		{
			model.province.provinceName = event.currentTarget.toString();
			/*trace(model.province.provinceName);*/
		}
		private function viewChangedHandler(event:IndexChangeEvent):void
		{
			model.city = view.selectedItems.toString();
			//dispatch(new GetCantavilNameEvent(GetCantavilNameEvent.CHANGE_CITY, view.selectedItems.toString()));
		}
		
		private function valueCommitHandler(event:FlexEvent):void
		{
			view.selectedIndex = 0;
		}
	}
}